﻿using RFIDSystem.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RFIDSystem
{
    public partial class InStockPrint : BaseForm
    {
        public DateTime BeginDate;
        public DateTime EndDate;

        public InStockPrint()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CheckStockPrint_Load(object sender, EventArgs e)
        {
            gridList.AutoGenerateColumns = false;

            dtBegin.Value = BeginDate;
            dtEnd.Value = EndDate;          

            BindList();
        }


        private void BindList()
        {
            this.lblCheckCode.Text = dtBegin.Value.ToString("yyyy-MM-dd");
            this.lblDateTime.Text = dtEnd.Value.ToString("yyyy-MM-dd");

            DateTime begin = dtBegin.Value.Date;
            DateTime end = dtEnd.Value.Date.AddDays(1);

            var query = from s in DAL.stock_in
                        where s.create_datetime >= begin && s.create_datetime <= end
                        select new
                        {
                            s.stock_id,
                            s.product_product.product_id,
                            s.product_product.product_catalog.product_catalog_name,
                            s.product_product.product_name,
                            s.product_product.product_model,
                            s.product_product.product_barcode,
                            s.product_product.product_rfid,
                            s.qty_in,
                            s.local,
                            s.create_datetime,
                        };

            var checkList = query.ToList();

            this.gridList.DataSource = checkList;
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //打印内容 为 整个Form
            //Image myFormImage;
            //myFormImage = new Bitmap(this.Width, this.Height);
            //Graphics g = Graphics.FromImage(myFormImage);
            //g.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
            //e.Graphics.DrawImage(myFormImage, 0, 0);

            Bitmap _NewBitmap = new Bitmap(panel1.Width, panel1.Height);
            panel1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
            e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);

        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
            {
                this.printDocument1.Print();
            }
        }

        private void btnPrintSetup_Click(object sender, EventArgs e)
        {
            this.pageSetupDialog1.ShowDialog();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            this.printPreviewDialog1.ShowDialog();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindList();
        }
    }
}
